package code.utils
{
	import code.obj.TimeObj;
	
	import main.App;
	
	import module.building.model.dataObj.BuildingObj;

	public class TimeUtil
	{
		public function TimeUtil()
		{
		}
		
		/**
		 * 返回剩余时间的字符串
		 * hh：mm：ss形式
		 */		
		public static function restTimeString(_restTime:int):String
		{
			var returnStr:String = "";
			var hour:int;
			var minute:int;
			var second:int;
			
			hour = _restTime / 3600;
			minute = (_restTime % 3600) / 60;
			second = (_restTime % 3600) % 60;
			
			if (hour < 10)
			{
				if (hour < 0)
				{
					hour=0;
				}
				returnStr += "0" + hour + ":";
			}
			else
			{
				returnStr += hour + ":";
			}
			
			if (minute < 10)
			{
				if (minute < 0)
				{
					minute=0;
				}
				returnStr += "0" + minute + ":";
			}
			else
			{
				returnStr +=minute + ":";
			}
			
			if (second < 10)
			{					
				if (second < 0)
				{
					second = 0;
				}
				returnStr += "0" + second;
			}
			else
			{
				returnStr += second;
			}
			
			return returnStr;
		}
		
		/**
		 * 将秒转换成时分秒格式 
		 * @param seconds 总秒数
		 * @return 时间类型，此类的toString()方法已重写
		 */
		public static function secondsToDate(seconds:Object):TimeObj
		{
			var time:int;
			if (seconds is String)
			{
				time = parseInt(seconds as String);
			}else if(seconds is int)
			{
				time = seconds as int;
			}
			var timeObj:TimeObj = new TimeObj();
			var hour:int = time/3600;
			var minute:int = (time/60)%60;
			var second:int = time%60;
			
			timeObj.hour = hour;
			timeObj.minute = minute;
			timeObj.second = second;
			
			return timeObj;
		}
		
		public static function minutesToData(minutes:Object):TimeObj
		{
			var time:int;
			if (minutes is String)
			{
				time = parseInt(minutes as String);
			}else if(minutes is int)
			{
				time = minutes as int;
			}
			
			var timeObj:TimeObj = new TimeObj();
			var hour:int = time/60;
			var minute:int = time%60;
			var second:int = 0;
			
			timeObj.hour = hour;
			timeObj.minute = minute;
			timeObj.second = second;
			
			return timeObj;
		}
	}
}